﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="msg_remind_window.aspx.cs" Inherits="Ccit.SysPlat.Remind.msg_remind_window" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>消息提醒</title> 
    <link href="../CSS/main.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script>
    <script src="../SCRIPT/jbase64.js" type="text/javascript"></script>


    <style type="text/css"> 
        #message{position:absolute;left:0;bottom:0;width:300px;height:0px;overflow:hidden}
    </style> 

    <script type="text/javascript" language="javascript">
      
      var oPopTimer = null; //弹出消息计时器
      var oLastRemindDate = null; //最后提醒时间         
      
      /* 弹出消息提醒 */ 
      function doPop(vType)
      {
         clearTimeout(oPopTimer);
         var vCurCount = document.getElementById("_hidCurCount").value;
         PageMethods.RemindMsg("Remind",vCurCount,"",vType,ClientCallBack);
      }
      
      function ClientCallBack(vResult) {
          if (vResult == null || vResult == "") return;
//          var vResultArr = vResult.split("_");
          //          var vType = vResultArr[0];
          eval("var resultObj=" + vResult);
          var operType = resultObj.operType;
          switch (operType)
          {
              case "checkPop":
                  var popFlag = resultObj.popFlag;
                  var flag = resultObj.flag;
                  if (popFlag == "1") //弹出消息提醒
                      doPop(flag);
                  break;
              case "remind":
                  var receiverCount = resultObj.receiverCount;
                  if (receiverCount != "0") {
                      document.getElementById("message").style.display = "block";

                      var msgSetObj = resultObj.msgSetObj;
                      //eval("var vResultObj = " + vResultArr[2]); //个人消息设置信息
                      document.getElementById("_hidSound").value = resultObj.oTone; //消息提示音

                      //eval("var vMsgObj=" + vResultArr[3]); //显示消息
                      var receiverObj = resultObj.receiverObj;

                      document.getElementById("sMsgCount").innerHTML = receiverCount;
                      document.getElementById("sSender").innerHTML = receiverObj.ReceiverId;
                      document.getElementById("sReceiveTime").innerHTML = receiverObj.ReceiveTime;
                      document.getElementById("txtareaContent").innerHTML = receiverObj.SendContent;

                      document.getElementById("_hidRecentId").value = receiverObj.SenderId; //发送人
                      document.getElementById("_hidMsgId").value = receiverObj.MsgId;

                      SetJumpStyle();

                      var flag = resultObj.flag;
                      if (receiverObj.MsgType == 1) //系统消息
                      {
                          document.getElementById("btnReply").style.display = "none";
                      }

                      if (flag == "onload")  //第一次加载时调用
                      {
                          var oRemindAgain = msgSetObj.oRemindTime * 60 * 1000;
                          oLastRemindDate = setInterval("doPop('again')", oRemindAgain);
                          showBox();
                      }
                      if (flag == "interval")  //按时间间隔获取消息
                      {
                          document.getElementById("message").style.display = "none";
                          var newMsgCount = resultObj.newMsgCount;
                          if (newMsgCount > 0) //有新消息
                          {
                              document.getElementById("message").style.display = "block";
                              window.clearInterval(oLastRemindDate);
                              oLastRemindDate = setInterval("doPop('again')", msgSetObj.oRemindTime * 60 * 1000);
                              showBox();
                          }
                      }
                      if (flag == "again") {
                          document.getElementById("message").style.display = "block";
                          showBox();
                      }
                  }
                  break;
              case "reply": 
                  var vRecentId = document.getElementById("_hidRecentId").value;
                  var vPageParam = "RecevierId="+vRecentId+"&PageSource=7";
                  var encodeParam = base64encode(vPageParam);
                  OpenWindow("msg_receive_back.aspx?"+encodeParam,"","700","600");
                  break;
             case "iKnow" : //我知道了
                  doNext();
                  break;
             case "delete" :
                  doNext();
                  break;              
          }
      }
      
      /* 返回下一条 */
      function doNext()
      {
          var oCurCount = parseInt(document.getElementById("_hidCurCount").value,"10");
          var vSumPage = parseInt(document.getElementById("sMsgCount").innerHTML,"10");   
          if(oCurCount == vSumPage)
            closeBox();
          else
          {
             if(vSumPage > oCurCount)
             {
                 doGetPageData("cur");
             }
          }
      }
      /* 我知道了 */
      function doKnow()
      {
          var vMsgId = document.getElementById("_hidMsgId").value;  
          PageMethods.RemindMsg("iKnow","",vMsgId,"page",ClientCallBack);
      }
      
      /* 回复 */
      function doReply()
      {  
            var vMsgId = document.getElementById("_hidMsgId").value;  
            PageMethods.RemindMsg("reply","",vMsgId,"page",ClientCallBack);  
       
      }
      /* 删除消息 */
      function doDel()
      {
        if(confirm("确认当期删除消息?"))
         {
            var vMsgId = document.getElementById("_hidMsgId").value;
            PageMethods.RemindMsg("delete","",vMsgId,"page",ClientCallBack);
         }
      }
      
      /* 获取分页消息 */
      function doGetPageData(vType)
      {
            var vCurCount = parseInt(document.getElementById("_hidCurCount").value,"10");
            switch(vType)
            {
                case "first":
                     vCurCount = 1;
                     break;
                case "before":
                     vCurCount--;
                     break;
                case "next":
                     vCurCount++;
                     break;
                case "last":
                     vCurCount = document.getElementById("sMsgCount").innerHTML;
                     break;
                case "cur" :
                     break;
            }
            document.getElementById("_hidCurCount").value=vCurCount;
            doPop("page");
        }
        /* 设置页面跳转链接样式 */
        function SetJumpStyle()
        {
            var oCurCount = parseInt(document.getElementById("_hidCurCount").value,"10");
            var vSumPage = parseInt(document.getElementById("sMsgCount").innerHTML,"10");
        
            var vhaFirst = document.getElementById("haFirst");
            var vhaBefore = document.getElementById("haBefore");
            var vhaNext = document.getElementById("haNext");
            var vhaLast = document.getElementById("haLast");
            
            if(vSumPage>1)
            {
                if(oCurCount==1)
                {
                    vhaFirst.disabled=true;
                    vhaFirst.removeAttribute("href");
                    vhaBefore.disabled=true;
                    vhaBefore.removeAttribute("href");
                    
                    vhaNext.disabled=false;
                    vhaNext.href="javascript:doGetPageData('next')";
                    vhaLast.disabled=false;
                    vhaLast.href="javascript:doGetPageData('last')";
                }
                else if(oCurCount==vSumPage)
                {
                    vhaNext.disabled=true;
                    vhaNext.removeAttribute("href");
                    vhaLast.disabled=true;
                    vhaLast.removeAttribute("href");
                    
                    vhaFirst.disabled=false;
                    vhaFirst.href="javascript:doGetPageData('first')";
                    vhaBefore.disabled=false;
                    vhaBefore.href="javascript:doGetPageData('before')";
                }
                else
                {
                   vhaFirst.disabled=false;
                   vhaFirst.href="javascript:doGetPageData('first')";
                   vhaBefore.disabled=false;
                   vhaBefore.href="javascript:doGetPageData('before')";
                   vhaNext.disabled=false;
                   vhaNext.href="javascript:doGetPageData('next')";
                   vhaLast.disabled=false;
                   vhaLast.href="javascript:doGetPageData('last')";
                }
            }
            else
            {
                vhaFirst.disabled=true;
                vhaFirst.removeAttribute("href");
                
                vhaBefore.disabled=true;
                vhaBefore.removeAttribute("href");
                
                vhaNext.disabled=true;
                vhaNext.removeAttribute("href");
                
                vhaLast.disabled=true;
                vhaLast.removeAttribute("href");
                
            }
      } 
      function onLoad()
      {
         document.getElementById("_hidCurCount").value = "1";
         var vCurCount = document.getElementById("_hidCurCount").value;
         PageMethods.RemindMsg("checkPop",vCurCount,"","onload",ClientCallBack); 
      }
    </script>
    
</head>
<body onload="onLoad()">
 <form id="form1" runat="server">
    
    
    <input type="hidden" runat="server" id="_hidRecentId" />
    <input type="hidden" runat="server" id="_hidCurCount" />
    <input type="hidden" runat="server" id="_hidMsgId" />
    <input type="hidden" runat="server" id="_hidSound" />
    
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
   <div id="message" onmouseout="startRun()" onmouseover="stopRun()"  style="display:none; text-align: center; width: 300px; height: 0px;
        border: 1px #919B9C solid; background: #F8F8F5;">
        <table class="tableborder" cellpadding="0" cellspacing="0" width="100%">
          <tr class="pformstrip" style="height:18px">
            <td>个人<font color="#6666FF">/系统</font>消息<font color="red"><span id="sRun">10</span></font>秒钟后关闭</td>
            <td align="right"><span id="sClose"><a href="javascript:closeBox()"><img src="../images/delete16.gif" /></a></span>&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" align="left">您有<font color="red"><span id="sMsgCount"></span></font>条新消息</td>
          </tr>
          <tr class="pfromleft">
            <td>
                来自&nbsp;<span id="sSender"></span>&nbsp;
                <span id="sReceiveTime"></span>
            </td>
            <td align="right">
                <a href="javascript:doGetPageData('first')" class="linktext" id="haFirst"><<</a>
                <a href="javascript:doGetPageData('before')" class="linktext" id="haBefore">上一条</a> 
                <a href="javascript:doGetPageData('next')" class="linktext" id="haNext">下一条</a>
                <a href="javascript:doGetPageData('last')" class="linktext" id="haLast">>></a>&nbsp;
            </td>
          </tr>
          <tr class="pfromleft">
            <td colspan="2" align="center">
              <textarea id="txtareaContent" disabled="disabled" class="textinput" runat="server" cols="30" style="width:98%; height:98px"></textarea>
            </td>
          </tr>
          <tr class="pformstrip" width="98%" >
            <td colspan="2" align="center" valign="top">
             <nobr>
              <input type="button" id="btnReply" class="button" value="回复" runat="server" onclick="doReply()"/>&nbsp;&nbsp;
              <input type="button" id="btnKnow" class="button" value="我知道了" runat="server" onclick="doKnow()" />&nbsp;&nbsp;
              <input type="button" id="btnDel" class="button" value="删除消息" runat="server" onclick="doDel()" />
            </nobr>
            </td>
          </tr>
        </table>
     </div>
     
    </form> 
</body>     
</html> 
<script language="javascript" type="text/javascript">
    function showBox(o){ 
        if (o==undefined) o=document.getElementById("message"); 
        o.style.height=o.clientHeight+2+"px"; 
        if (o.clientHeight==2)
		{
		    var sound = document.getElementById("_hidSound").value;
			document.getElementById("message").innerHTML+="<PRE><BGSOUND balance=0 src='sound.wav' volume=0 loop=1></PRE>";
		}
		
        if (o.clientHeight<200) 
        {
           setTimeout(function(){showBox(o)},5);    
        }
        if(o.clientHeight == 200)
        {
            startRun();
        }
    }
    function closeBox()
    {
		var o=document.getElementById("message");
        o.style.display="block";
		o.style.height=o.clientHeight-2+"px";
        if(o.clientHeight>0)
			setTimeout(function(){closeBox()},5);
			
		if(o.clientHeight==0)
		{
			document.getElementById("sRun").innerHTML=10;
			stopRun();
			o.style.display="none";
		    oPopTimer = setTimeout("doPop('interval')",10000);
		}
    }
    
    
    function run(){
	    var sRun = document.getElementById("sRun");
	    if(sRun.innerHTML == 0){
	      return false;
	    }
        sRun.innerHTML = sRun.innerHTML * 1 - 1;
        if(sRun.innerHTML == 0)
            closeBox();
    }
    var oTimer = null;  //秒表计时器
    function startRun() //开始计时
    {
      oTimer = setInterval("run();", 1000); 
    }
    function stopRun()  //停止计时
    {
      window.clearInterval(oTimer);     //清除时间间隔 
      return false;
    }
</script>